Page({
  data: {
    orderId: '',
    amount: '',
    paymentTime: '',
    orderInfo: {},
    loading: false
  },
  
  onLoad: function(options) {
    // 打印完整的参数对象到控制台
    console.log('==============================');
    console.log('支付成功页面接收到的订单详情数据:');
    console.log('------------------------------');
    console.log('完整参数对象:', options);
    
    // 如果有订单ID，打印订单相关信息
    if (options.orderId) {
      console.log('订单ID:', options.orderId);
    }
    
    // 如果有金额，打印金额信息
    if (options.amount) {
      console.log('支付金额:', options.amount);
    }
    
    // 打印所有其他参数
    const allParams = Object.keys(options);
    if (allParams.length > 0) {
      console.log('所有接收到的参数列表:');
      allParams.forEach(paramName => {
        console.log(`  ${paramName}: ${options[paramName]}`);
      });
    } else {
      console.log('未接收到任何参数');
    }
    
    console.log('==============================');
    
    // 设置页面数据
    this.setData({
      orderId: options.orderId || '',
      amount: options.amount || '',
      paymentTime: this.formatCurrentTime()
    });
    
    // 可以在这里添加获取订单详情的逻辑
    // this.fetchOrderDetail(options.orderId);
  },
  
  // 格式化当前时间
  formatCurrentTime: function() {
    const now = new Date();
    const year = now.getFullYear();
    const month = (now.getMonth() + 1).toString().padStart(2, '0');
    const day = now.getDate().toString().padStart(2, '0');
    const hours = now.getHours().toString().padStart(2, '0');
    const minutes = now.getMinutes().toString().padStart(2, '0');
    const seconds = now.getSeconds().toString().padStart(2, '0');
    
    return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
  },
  
  // 获取订单详情（如果需要）
  fetchOrderDetail: function(orderId) {
    if (!orderId) return;
    
    this.setData({ loading: true });
    
    // 这里可以添加实际的API调用逻辑
    // 示例：
    /*
    wx.request({
      url: 'https://api.example.com/orders/' + orderId,
      method: 'GET',
      success: (res) => {
        this.setData({
          orderInfo: res.data,
          loading: false
        });
      },
      fail: (err) => {
        console.error('获取订单详情失败:', err);
        this.setData({ loading: false });
      }
    });
    */
  },
  
  // 选择收货地址 - 跳转到地址填写页面
  selectAddress: function() {
    if (this.data.orderId) {
      wx.navigateTo({
        url: `/pages/order-address/order-address?orderId=${this.data.orderId}`
      });
    } else {
      wx.showToast({
        title: '订单ID不存在',
        icon: 'none'
      });
    }
  },
  
  // 查看订单详情
  viewOrderDetail: function() {
    if (this.data.orderId) {
      wx.navigateTo({
        url: `/pages/order-detail/order-detail?orderId=${this.data.orderId}`
      });
    } else {
      wx.showToast({
        title: '订单ID不存在',
        icon: 'none'
      });
    }
  },
  
  // 返回首页
  backToHome: function() {
    wx.switchTab({
      url: '/pages/index/index'
    });
  }
});